﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Best.SmartCms.API.Migrations
{
    public partial class order : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Address",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    
                    Name = table.Column<string>(maxLength: 50, nullable: true),
                    Province = table.Column<string>(maxLength: 50, nullable: true),
                    City = table.Column<string>(maxLength: 50, nullable: true),
                    County = table.Column<string>(maxLength: 50, nullable: true),
                    Address1 = table.Column<string>(maxLength: 100, nullable: true),
                    Phone = table.Column<string>(maxLength: 15, nullable: true),
                    CreatedTime = table.Column<DateTime>(nullable: true),
                    CreatorId = table.Column<long>(nullable: true),
                    CreatorName = table.Column<string>(maxLength: 50, nullable: true),
                    UpdatedTime = table.Column<DateTime>(nullable: true),
                    UpdatorId = table.Column<long>(nullable: true),
                    UpdatorName = table.Column<string>(maxLength: 50, nullable: true),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Address", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Area",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ParentId = table.Column<long>(nullable: false),
                    CityName = table.Column<string>(nullable: true),
                    Enabled = table.Column<bool>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Area", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Order",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    
                    OrderNumber = table.Column<string>(maxLength: 50, nullable: true),
                    AddressId = table.Column<long>(nullable: true),
                    CustomerId = table.Column<long>(nullable: true),
                    PayType = table.Column<int>(nullable: false),
                    ShippingMethod = table.Column<int>(nullable: true),
                    Status = table.Column<int>(nullable: false),
                    OrderTotal = table.Column<decimal>(nullable: true),
                    OrderDiscount = table.Column<decimal>(nullable: true),
                    RefundedAmount = table.Column<decimal>(nullable: true),
                    Deleted = table.Column<bool>(nullable: true),
                    CreatedTime = table.Column<DateTime>(nullable: true),
                    CreatorId = table.Column<long>(nullable: true),
                    CreatorName = table.Column<string>(maxLength: 50, nullable: true),
                    UpdatedTime = table.Column<DateTime>(nullable: true),
                    UpdatorId = table.Column<long>(nullable: true),
                    UpdatorName = table.Column<string>(maxLength: 50, nullable: true),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Order", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "OrderItem",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    
                    OrderId = table.Column<long>(nullable: false),
                    ProductId = table.Column<long>(nullable: false),
                    Quantity = table.Column<int>(nullable: true),
                    UnitPrice = table.Column<decimal>(nullable: true),
                    DiscountAmount = table.Column<decimal>(nullable: true),
                    CreatedTime = table.Column<DateTime>(nullable: true),
                    CreatorId = table.Column<long>(nullable: true),
                    CreatorName = table.Column<string>(maxLength: 50, nullable: true),
                    UpdatedTime = table.Column<DateTime>(nullable: true),
                    UpdatorId = table.Column<long>(nullable: true),
                    UpdatorName = table.Column<string>(maxLength: 50, nullable: true),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OrderItem", x => x.Id);
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Address");

            migrationBuilder.DropTable(
                name: "Area");

            migrationBuilder.DropTable(
                name: "Order");

            migrationBuilder.DropTable(
                name: "OrderItem");
        }
    }
}
